package org.summerframework.component.upload.image.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.summerframework.component.mybatisplus.AbstractBasePlusService;
import org.summerframework.component.upload.image.model.dao.FileImageDAO;
import org.summerframework.component.upload.image.model.domain.FileImageDO;
import org.summerframework.component.upload.image.service.FileImageService;
import org.summerframework.component.upload.image.service.dto.FileImageDTO;
import org.summerframework.component.upload.image.service.dto.FileImageQueryDTO;

import java.util.Objects;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service("fileImageService")
public class FileImageServiceImpl extends AbstractBasePlusService<FileImageDAO, FileImageDTO, FileImageQueryDTO, FileImageDO> implements FileImageService {

    @Override
    public Wrapper<FileImageDO> getWrapper(FileImageQueryDTO query) {
        return Wrappers.<FileImageDO>lambdaQuery()
                .orderBy(Objects.nonNull(query.getOrderById()), query.getOrderById() != null ? query.getOrderById() : false, FileImageDO::getId)
                .eq(StringUtils.isNotBlank(query.getSpecifications()), FileImageDO::getSpecifications, query.getSpecifications())
                .eq(Objects.nonNull(query.getFileId()), FileImageDO::getFileId, query.getFileId());
    }

    @Override
    public FileImageDTO selectBySpecifications(Long fileId, String specifications) {
        return selectOne(FileImageQueryDTO.builder().fileId(fileId).specifications(specifications).build());
    }
}
